<?php
	require_once $ubi['SERVER']['SERVER_ROOT'] . '/admin/dao/daoQuestionItem.php';
	require_once $ubi['SERVER']['SERVER_ROOT'] . '/admin/model/question.php';
	
	class QuestionItemBus {
		private $_questionItemDao;
		
		public function __construct() {
			$this->_questionItemDao = new QuestionItemDao();				
		}
		
		public function addQuestionItem($xmlString, $catID) {
			$this->_questionItemDao->deleteQuestionItem($catID);
			
			$xml = simplexml_load_string($xmlString);
			foreach ($xml->Question as $question) {
				$question_item = new QuestionModel();
				
				$nodeAnswers = $question->xpath('answers');
				
				$question_item->setAnswers($nodeAnswers[0]->asXML());
				$question_item->setCategoryID($catID);
				$attr = $question->attributes();
				$question_item->setQuestion($attr['content']);
				
				$this->_questionItemDao->addQuestionItem($question_item);
			} 
			
			return 1;
		}
	}
?>